<?php
namespace AdminApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ReviewsApiController extends AbstractRestfulController
{
    public function getList()
    {
		header('Access-Control-Allow-Origin: *');
		$ReviewsTable=$this->getServiceLocator()->get('Models\Model\ReviewsFactory');
		$reviews = $ReviewsTable->getAllReviewsAndRatings()->toArray();
		if(count($reviews)!=0){
				return new JsonModel(array(
				    'value'	            => 1,
					'result'		    => $reviews,
				));
			}else{
				return new JsonModel(array(
					'value'	            => 0,
					'result'		    => 	'empty',
				));
			}
    }
    public function get($id)
    {	
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		$explodeId=explode('-',$id);
		 if($explodeId[0]=='order_status'){
			$order_id=$explodeId[1];
			$checkOrder = $userMedicineOrderTable->checkOrder_status($order_id);
			if($checkOrder!=0){
				$orderStatus = $userMedicineOrderTable->orderStatus($order_id)->current()->status;
				if($orderStatus==0){
					return new JsonModel(array(
						'value'		    => 	0,
					));
				}else if($orderStatus==1){
					return new JsonModel(array(
						'value'		    => 1,
					));
				}else if($orderStatus==2){
					return new JsonModel(array(
						'value'		    => 2,
					));
				}else{
					return new JsonModel(array(
						'value'		    => 3,
					));
				}
			}else{
				return new JsonModel(array(
					'value'		    => 4,
				));
			}
		}
    }
    public function create($oder)
    {
		
    }
    public function update($shop_id,$id)
    {
		header('Access-Control-Allow-Origin: *');
		$ReviewsTable=$this->getServiceLocator()->get('Models\Model\ReviewsFactory');
		$values=explode('-',$shop_id);
		$shop_Id=$values[0];
		$reviews = $ReviewsTable->getReviewsAndRatingsShop($shop_id)->toArray();
		if(count($reviews)!=0){
			return new JsonModel(array(
				'value'	            => 1,
				'result'		=> $reviews,
			));
		}else{
			return new JsonModel(array(
				'value'	            => 0,
				'reviews'		=> 	'empty',
			));
		}
	}
    public function delete($id)
    {
       
    }
}